package com.gxa.modules.service.impl;

import com.gxa.common.vo.JsonResult;
import com.gxa.common.vo.ResultVo;
import com.gxa.modules.mapper.MemberMapper;
import com.gxa.modules.pojo.Member;
import com.gxa.modules.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class MemberServiceImpl implements MemberService {
    @Autowired(required = false)
    private MemberMapper memberMapper;
    @Override
    public JsonResult queryMember(Integer page, Integer limit) {
        JsonResult r=new JsonResult();
        Integer parma1=(page-1)*limit;
        Integer parma2=limit;
        Integer count=memberMapper.findCount();
        List<Map> employeeList = memberMapper.queryMember(parma1,parma2);
        r.setCode(200);
        r.setMsg("查询成功");
        r.setCount(count);
        r.setData(employeeList);
        return r;
    }

    @Override
    public JsonResult queryMemberByNumber(Integer member_cd) {
        JsonResult r=new JsonResult();
        r.setCode(200);
        r.setMsg("查询成功");
        Map member =memberMapper.queryMemberByNumber(member_cd);
        r.setData(member);
        return r;
    }

    @Override
    public ResultVo addMember(Member member) {
        ResultVo r = new ResultVo();
        memberMapper.addMember(member);
        r.setCode(200);
        r.setMsg("添加成功");
        return  r;
    }

    @Override
    public ResultVo updateMemberPwd(Integer member_cd,String newPwd) {
        ResultVo r = new ResultVo();
        memberMapper.updateMemberPwd(member_cd,newPwd);
        r.setCode(200);
        r.setMsg("修改成功");
        return  r;
    }

    @Override
    public ResultVo editMember(Member member) {
        ResultVo r = new ResultVo();
        memberMapper.editMember(member);
        r.setCode(200);
        r.setMsg("修改成功");
        return  r;
    }

    @Override
    public JsonResult queryInvest(Integer page, Integer limit) {
        JsonResult r=new JsonResult();
        Integer parma1=(page-1)*limit;
        Integer parma2=limit;
        Integer count=memberMapper.findInvestCount();
        List<Map> employeeList = memberMapper.queryInvest(parma1,parma2);
        r.setCode(200);
        r.setMsg("查询成功");
        r.setCount(count);
        r.setData(employeeList);
        return r;
    }

    @Override
    public JsonResult searchInvest(Integer invest_number) {
        JsonResult r=new JsonResult();
        r.setCode(200);
        r.setMsg("查询成功");
        Map invest =memberMapper.searchInvest(invest_number);
        r.setData(invest);
        return r;
    }

    @Override
    public JsonResult queryTodayInvest(Integer currentPage, Integer pageSize) {

        JsonResult r=new JsonResult();
        Integer parma1=(currentPage-1)*pageSize;
        Integer parma2=pageSize;
        Integer count=memberMapper.queryTodayInvestCount();
        List<Map> todayInvestList = memberMapper.queryTodayInvest(parma1,parma2);
        r.setCode(200);
        r.setMsg("查询成功");
        r.setCount(count);
        r.setData(todayInvestList);
        return r;
    }

    @Override
    public JsonResult queryYesterdayInvest(Integer currentPage, Integer pageSize) {
        JsonResult r=new JsonResult();
        Integer parma1=(currentPage-1)*pageSize;
        Integer parma2=pageSize;
        Integer count=memberMapper.queryYesterdayInvestCount();
        List<Map> yesterdayInvest = memberMapper.queryYesterdayInvest(parma1,parma2);
        r.setCode(200);
        r.setMsg("查询成功");
        r.setCount(count);
        r.setData(yesterdayInvest);
        return r;
    }

    @Override
    public JsonResult queryWeekInvest(Integer currentPage, Integer pageSize) {
        JsonResult r=new JsonResult();
        Integer parma1=(currentPage-1)*pageSize;
        Integer parma2=pageSize;
        Integer count=memberMapper.queryWeekInvestCount();
        List<Map> weekInvestList = memberMapper.queryWeekInvest(parma1,parma2);
        r.setCode(200);
        r.setMsg("查询成功");
        r.setCount(count);
        r.setData(weekInvestList);
        return r;
    }

    @Override
    public JsonResult queryMonthInvest(Integer currentPage, Integer pageSize) {
        JsonResult r=new JsonResult();
        Integer parma1=(currentPage-1)*pageSize;
        Integer parma2=pageSize;
        Integer count=memberMapper.queryMonthInvestCount();
        List<Map> monthInvestList = memberMapper.queryMonthInvest(parma1,parma2);
        r.setCode(200);
        r.setMsg("查询成功");
        r.setCount(count);
        r.setData(monthInvestList);
        return r;
    }

    @Override
    public JsonResult queryBetweenTimeInvest(Integer currentPage, Integer pageSize, String beforeTime, String afterTime) {
        JsonResult r=new JsonResult();
        Integer parma1=(currentPage-1)*pageSize;
        Integer parma2=pageSize;
        Integer count=memberMapper.queryBetweenTimeInvestCount(beforeTime,afterTime);
        List<Map> betweenTimeInvestList = memberMapper.queryBetweenTimeInvest(parma1,parma2,beforeTime,afterTime);
        r.setCode(200);
        r.setMsg("查询成功");
        r.setCount(count);
        r.setData(betweenTimeInvestList);
        return r;
    }

}
